}
#define conv_rgb8_rgbAF conv_rgb8_rgbaF
+#define conv_gamma_rgbaF_gamma_rgbAF conv_rgbaF_rgbAF
+#define conv_gamma_rgbAF_gamma_rgbaF conv_rgbAF_rgbaF
int init (void);
babl_component ("Ba"),
babl_component ("A"),
NULL);
+
+
+ const Babl *gamma_rgbaF = babl_format_new (
+ babl_model ("R'G'B'A"),
+ babl_type ("float"),
+ babl_component ("R'"),
+ babl_component ("G'"),
+ babl_component ("B'"),
+ babl_component ("A"),
+ NULL);
+ const Babl *gamma_rgbAF = babl_format_new (
+ babl_model ("R'aG'aB'aA"),
+ babl_type ("float"),
+ babl_component ("R'a"),
+ babl_component ("G'a"),
+ babl_component ("B'a"),
+ babl_component ("A"),
+ NULL);
const Babl *lrgba8 = babl_format_new (
babl_model ("RGBA"),
o (rgbaF, rgbAF);
o (rgbAF, rgbaF);
+
+ o (gamma_rgbaF, gamma_rgbAF);
+ o (gamma_rgbAF, gamma_rgbaF);
+
o (rgbAF, lrgba8);
o (rgb8, rgbaF);
o (rgb8, rgbAF);
--- /dev/null
+#include <stdlib.h>
+#include <stdint.h>
+#include "babl.h"
+
+int init (void);
+
+static inline long
+float_to_u8 (unsigned char *src_char, unsigned char *dst, long samples)
+{
+ float *src = (float *)src_char;
+ long n = samples;
+ while (n--)
+ {
+ float r = src[0];
+ float g = src[1];
+ float b = src[2];
+ float a = src[3];
+
+ dst[0] = (r >= 1.0f) ? 0xFF : ((r <= 0.0f) ? 0x0 : 0xFF * r + 0.5f);
+ dst[1] = (g >= 1.0f) ? 0xFF : ((g <= 0.0f) ? 0x0 : 0xFF * g + 0.5f);
+ dst[2] = (b >= 1.0f) ? 0xFF : ((b <= 0.0f) ? 0x0 : 0xFF * b + 0.5f);
+ dst[3] = (a >= 1.0f) ? 0xFF : ((a <= 0.0f) ? 0x0 : 0xFF * a + 0.5f);
+
+ dst += 4;
+ src += 4;
+ }
+ return samples;
+}
+
+static inline long
+float_pre_to_u8_pre (unsigned char *src_char, unsigned char *dst, long samples)
+{
+ float *src = (float *)src_char;
+ long n = samples;
+ while (n--)
+ {
+ float r = src[0];
+ float g = src[1];
+ float b = src[2];
+ float a = src[3];
+
+ if (a > 1.0f) {
+ r /= a;
+ g /= a;
+ b /= a;
+ a /= a;
+ }
+
+ dst[0] = (r >= 1.0f) ? 0xFF : ((r <= 0.0f) ? 0x0 : 0xFF * r + 0.5f);
+ dst[1] = (g >= 1.0f) ? 0xFF : ((g <= 0.0f) ? 0x0 : 0xFF * g + 0.5f);
+ dst[2] = (b >= 1.0f) ? 0xFF : ((b <= 0.0f) ? 0x0 : 0xFF * b + 0.5f);
+ dst[3] = (a >= 1.0f) ? 0xFF : ((a <= 0.0f) ? 0x0 : 0xFF * a + 0.5f);
+
+ dst += 4;
+ src += 4;
+
+ }
+ return samples;
+}
+
+static inline long
+float_to_u16 (unsigned char *src_char, unsigned char *dst_char, long samples)
+{
+ float *src = (float *)src_char;
+ uint16_t *dst = (uint16_t *)dst_char;
+ long n = samples;
+ while (n--)
+ {
+ float r = src[0];
+ float g = src[1];
+ float b = src[2];
+ float a = src[3];
+
+ dst[0] = (r >= 1.0f) ? 0xFFFF : ((r <= 0.0f) ? 0x0 : 0xFFFF * r + 0.5f);
+ dst[1] = (g >= 1.0f) ? 0xFFFF : ((g <= 0.0f) ? 0x0 : 0xFFFF * g + 0.5f);
+ dst[2] = (b >= 1.0f) ? 0xFFFF : ((b <= 0.0f) ? 0x0 : 0xFFFF * b + 0.5f);
+ dst[3] = (a >= 1.0f) ? 0xFFFF : ((a <= 0.0f) ? 0x0 : 0xFFFF * a + 0.5f);
+
+ dst += 4;
+ src += 4;
+ }
+ return samples;
+}
+
+static inline long
+float_pre_to_u16_pre (unsigned char *src_char, unsigned char *dst_char, long samples)
+{
+ float *src = (float *)src_char;
+ uint16_t *dst = (uint16_t *)dst_char;
+ long n = samples;
+ while (n--)
+ {
+ float r = src[0];
+ float g = src[1];
+ float b = src[2];
+ float a = src[3];
+
+ if (a > 1.0f) {
+ r /= a;
+ g /= a;
+ b /= a;
+ a /= a;
+ }
+
+ dst[0] = (r >= 1.0f) ? 0xFFFF : ((r <= 0.0f) ? 0x0 : 0xFFFF * r + 0.5f);
+ dst[1] = (g >= 1.0f) ? 0xFFFF : ((g <= 0.0f) ? 0x0 : 0xFFFF * g + 0.5f);
+ dst[2] = (b >= 1.0f) ? 0xFFFF : ((b <= 0.0f) ? 0x0 : 0xFFFF * b + 0.5f);
+ dst[3] = (a >= 1.0f) ? 0xFFFF : ((a <= 0.0f) ? 0x0 : 0xFFFF * a + 0.5f);
+
+ dst += 4;
+ src += 4;
+ }
+ return samples;
+}
+
+int
+init (void)
+{
+ /* float and u8 */
+ babl_conversion_new (babl_format ("R'G'B'A float"),
+ babl_format ("R'G'B'A u8"),
+ "linear",
+ float_to_u8,
+ NULL);
+ babl_conversion_new (babl_format ("RGBA float"),
+ babl_format ("RGBA u8"),
+ "linear",
+ float_to_u8,
+ NULL);
+ babl_conversion_new (babl_format ("R'aG'aB'aA float"),
+ babl_format ("R'aG'aB'aA u8"),
+ "linear",
+ float_pre_to_u8_pre,
+ NULL);
+ babl_conversion_new (babl_format ("RaGaBaA float"),
+ babl_format ("RaGaBaA u8"),
+ "linear",
+ float_pre_to_u8_pre,
+ NULL);
+
+ /* float and u16 */
+ babl_conversion_new (babl_format ("R'G'B'A float"),
+ babl_format ("R'G'B'A u16"),
+ "linear",
+ float_to_u16,
+ NULL);
+ babl_conversion_new (babl_format ("RGBA float"),
+ babl_format ("RGBA u16"),
+ "linear",
+ float_to_u16,
+ NULL);
+ babl_conversion_new (babl_format ("R'aG'aB'aA float"),
+ babl_format ("R'aG'aB'aA u16"),
+ "linear",
+ float_pre_to_u16_pre,
+ NULL);
+ babl_conversion_new (babl_format ("RaGaBaA float"),
+ babl_format ("RaGaBaA u16"),
+ "linear",
+ float_pre_to_u16_pre,
+ NULL);
+
+ return 0;
+}
}
{
- float in[][4] = {{ 0.21582, -0.55, -0.14, 1.0 }, {0.2, 0.301, 0.5, 0.6}, {0.0, 3.0, 6.0, 3.0}};
+ /* (0.5 / 0.6) * 255 = 212.5, I'm not going to worry about rounding that close... */
+ float in[][4] = {{ 0.21582, -0.55, -0.14, 1.0 }, {0.2, 0.301, 0.49998, 0.6}, {0.0, 3.0, 6.0, 3.0}};
unsigned char out[][4] = {{55, 0, 0, 255 }, {85,128,212,153}, {0,255,255,255}};
CHECK_CONV("float -> u8 6", unsigned char,